package com.xydtech.ecard.ftp.controller;

import com.xydtech.common.annotation.RsaRequest;
import com.xydtech.common.enums.ResultStatus;
import com.xydtech.common.model.ResponseModel;
import com.xydtech.ecard.ecard.controller.EcardApiBaseController;
import com.xydtech.ecard.ftp.domain.EcardApiFtpInfo;
import com.xydtech.ecard.ftp.domain.EcardFtpResultsSummaryBO;
import com.xydtech.ecard.ftp.service.IEcardFtpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: liliya
 * @Description:
 * @Date: Created in 2023/8/15 16:33
 * @Modified:
 */
@Controller
@Api(tags = "电子名片-FTP接口")
@RequestMapping("/ecardSaasApi/ftp")
public class EcardFtpController extends EcardApiBaseController {

    private IEcardFtpService ecardFtpService;

    public EcardFtpController(IEcardFtpService ecardFtpService) {
        this.ecardFtpService = ecardFtpService;
    }


    /**
     * ftp计算入口
     * @param ecardApiFtpInfo
     * @return
     */
    @RequestMapping(value = "/calculate",method = {RequestMethod.POST}, consumes = "application/json")
    @ApiOperation(value = "电子名片-ftp计算入口", notes = "电子名片-ftp计算入口")
    @ApiResponses({@ApiResponse(code = 0, message = "OK", response = ResponseModel.class),
            @ApiResponse(code=200,message = "data",response =EcardFtpResultsSummaryBO.class )
    })
    //@PassToken//TODO 测完记得删除
    @RsaRequest//TODO 测试完记得加
    @ResponseBody
    public ResponseModel calculate(@Validated @RequestBody EcardApiFtpInfo ecardApiFtpInfo) {
        try {
            if (ecardApiFtpInfo == null) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }

            //TODO userCode从缓存中取

            return ResponseModel.okToJSON(ecardFtpService.calculateFtpEntrance(ecardApiFtpInfo));
        } catch (Exception ex) {
            return ResponseModel.error(ex);
        }
    }


    public IEcardFtpService getEcardFtpService() {
        return ecardFtpService;
    }

    public void setEcardFtpService(IEcardFtpService ecardFtpService) {
        this.ecardFtpService = ecardFtpService;
    }
}
